package org.sword.wechat4j.driver;

import org.sword.wechat4j.request.BaseMessage;
import org.sword.wechat4j.response.*;

import java.util.List;

/**
 * 响应驱动
 * Created by sean on 2016-07-22-0022.
 */
public class HandleDriver {

    private WechatResponse wechatResponse;
    private BaseMessage baseMessage;

    public WechatResponse service(BaseMessage baseMessage) {
        this.baseMessage = baseMessage;
        this.wechatResponse = new WechatResponse();
        responseBase();
        return wechatResponse;
    }

    /**
     * 响应数据基础构造
     */
    private void responseBase() {
        wechatResponse.setToUserName(baseMessage.getFromUserName());
        wechatResponse.setFromUserName(baseMessage.getToUserName());
        wechatResponse.setCreateTime(baseMessage.getCreateTime());
    }

    /**
     * 文本消息响应
     *
     * @param content 文本信息
     */
    public final void responseText(String content) {
        wechatResponse.setContent(content);
    }

    /**
     * 图片消息响应
     * @param mediaId 素材
     */
    public final void responseImage(String mediaId) {
        ImageResponse image = new ImageResponse();
        image.setMediaId(mediaId);
        wechatResponse.setImage(image);
    }

    /**
     * 语音消息响应
     * @param mediaId 素材
     */
    public final void responseVoice(String mediaId) {
        VoiceResponse voice = new VoiceResponse();
        voice.setMediaId(mediaId);
        wechatResponse.setVoice(voice);
    }

    /**
     * 视频消息响应
     * @param video 视频
     */
    public final void responseVideo(VideoResponse video) {
        wechatResponse.setVideo(video);
    }

    /**
     * music 消息响应
     * @param music music
     */
    public final void responseMusic(MusicResponse music) {
        wechatResponse.setMusic(music);
    }

    /**
     * 多图文消息响应
     * @param articles articles
     */
    public final void responseNews(List<ArticleResponse> articles) {
        wechatResponse.setArticleCount(articles.size());
        wechatResponse.setArticle(articles);
    }

    /**
     * 转发客服消息
     * @param kfAccount 客服帐号
     */
    public final void responseTrans(String kfAccount) {
        TransferCustomerServiceResponse transferCustomerServiceResponse = new TransferCustomerServiceResponse();
        transferCustomerServiceResponse.setKfAccount(kfAccount);
        wechatResponse.setTransInfo(transferCustomerServiceResponse);
    }
}
